package world.snowcrystal.configuration;


import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
import world.snowcrystal.properties.OssProperties;

@Configuration
@EnableConfigurationProperties({OssProperties.class})
public class OssConfiguration {

    @Autowired
    private OssProperties properties;


    @Bean(destroyMethod = "shutdown")
    @Lazy
    @ConditionalOnMissingBean(OSS.class)
    public OSS ossClient() {
        return new OSSClientBuilder().build(properties.getEndpoint(),
                properties.getAccessKey(),
                properties.getSecretKey());
    }


}
